package com.android.videotest.music;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;

public class ImageUtil {
    /**
     * 根据专辑ID获取本地专辑封面图
     *
     * @param album_id 专辑ID
     * @return
     */
    public static Bitmap getLocalAlbumImage(Context context,int album_id) {
        String uriAlbums = "content://media/external/audio/albums";
        String[] projection = new String[]{"album_art"};
        Cursor cur = context.getContentResolver().query(Uri.parse(uriAlbums + "/" + album_id), projection, null, null, null);
        String album_art = null;
        if (cur != null && cur.getCount() > 0 && cur.getColumnCount() > 0) {
            cur.moveToNext();
            album_art = cur.getString(0);
        }
        if (cur != null) {
            cur.close();
        }
        Bitmap bm = null;
        if (album_art != null) {
            bm = BitmapFactory.decodeFile(album_art);
        } else {
//            bm = BitmapFactory.decodeResource(getResources(), R.drawable.default_cover);
        }
        return bm;
    }

//    public static String getAlbumImage(Context context, int albumId) {
//
//    }
}
